package datos;

import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;

import conexion.Conexion;

public class AccionesTipoPago {

	public static ArrayList<TipoPago> getAll(){
		ArrayList<TipoPago> tipos=new ArrayList<TipoPago>();
		try {
			Statement stm=Conexion.conectar().createStatement();
			ResultSet rs=stm.executeQuery("select * from tipo_pago");
			while (rs.next()){
				TipoPago t=new TipoPago(rs.getInt("idTipoPago"), rs.getString("tipo"));
				tipos.add(t);
			}
			stm.close();
			Conexion.desconectar();
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return tipos;
	}
	
	public static TipoPago getOne(int idTipoPago){
		TipoPago tp=null;
		try{
			Statement stm=Conexion.conectar().createStatement();
			ResultSet rs=stm.executeQuery("select * from tipo_pago where idTipoPago="+idTipoPago);
			while (rs.next()){
				tp=new TipoPago(rs.getInt("idTipoPago"), rs.getString("tipo"));
				return tp;
			}
			
		}catch(Exception e){
			e.printStackTrace();
		}
		return tp;
	}
}
